﻿
CREATE FUNCTION [dbo].[GetOrderString] 
(
	@Cont_par TipCont	
)
RETURNS varchar(100)
AS
BEGIN
	DECLARE @Cont TipCont
	SET @Cont = LTRIM(RTRIM(@Cont_par))
	DECLARE @Ret TipCont 
	DECLARE @LenC int
	SET @Ret=@Cont 
	IF CHARINDEX('.',@cont)<1 
		BEGIN 
		SET @LenC = 0
		IF LEN(@Cont)< 10
			SET @LenC = 10-LEN(@Cont)
		SET @Ret = RIGHT(@Cont, 10-@LenC) + REPLICATE('0', @LenC) +	REPLICATE('0', 90)
		END
	ELSE
		BEGIN
			DECLARE @pointPoz int
			DECLARE @bucCont varchar(100)
			--numara cate puncte are
			DECLARE @i int,@Cate int
			SET @i=1
			SET @Cate=10
			SET @Ret = ''	
			SET @pointPoz = CHARINDEX('.',@Cont)
			WHILE (@pointPoz < LEN(@Cont)) AND (@pointPoz>0) AND @i<10
			BEGIN
				SET @LenC = 0
				IF @pointPoz< 11
					SET @LenC =  11 - @pointPoz
				IF @i=1
					SET @bucCont = RIGHT(SUBSTRING(@Cont,1,@pointPoz-1),10-@LenC) + REPLICATE('0',@LenC)	
				ELSE
					SET @bucCont = REPLICATE('0',@LenC)	+ RIGHT(SUBSTRING(@Cont,1,@pointPoz-1),10-@LenC)
				SET @Cont=SUBSTRING(@Cont,@pointPoz+1,LEN(@Cont))
				SET @pointPoz = CHARINDEX('.',@Cont)
				SET @Ret = @Ret + @bucCont
				SET @i=@i+1
			END
			SET @LenC = 0
			IF LEN(@Cont)< 10
				SET @LenC = 10-LEN(@Cont)
			SET @Ret = @Ret + REPLICATE('0',@LenC) + RIGHT(@Cont, 10-@LenC)  + REPLICATE('0', (10-@i)*10)
		END

	

	-- Return the result of the function
	RETURN @Ret

END